

<!doctype html>

<html lang="en" data-content_root="../../">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>skidl.design_class &#8212; SKiDL 2.2.0 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
    <link rel="stylesheet" type="text/css" href="../../_static/bizstyle.css?v=a66e137f" />
    
    <script src="../../_static/documentation_options.js?v=b21de401"></script>
    <script src="../../_static/doctools.js?v=9bcbadda"></script>
    <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../../_static/bizstyle.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <!--[if lt IE 9]>
    <script src="_static/css3-mediaqueries.js"></script>
    <![endif]-->
  </head><body>
    <h1 id="site-title"><a href="../../../../"><img src="../../../../images/slim_banner.png" width="100%"></a></h1>
    
    <div class="related" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SKiDL 2.2.0 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">skidl.design_class</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <h1>Source code for skidl.design_class</h1><div class="highlight"><pre>
<span></span><span class="c1"># -*- coding: utf-8 -*-</span>
<span class="c1"># The MIT License (MIT) - Copyright (c) Dave Vandenbout.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Design class module for SKIDL.</span>

<span class="sd">This module provides classes for managing design elements like parts and nets,</span>
<span class="sd">including their classification and organization within circuits. It defines</span>
<span class="sd">base classes for design elements and specialized collections for managing</span>
<span class="sd">specific types like part classes and net classes.</span>
<span class="sd">&quot;&quot;&quot;</span>


<span class="kn">from</span> <span class="nn">abc</span> <span class="kn">import</span> <span class="n">ABC</span>

<span class="kn">from</span> <span class="nn">.logger</span> <span class="kn">import</span> <span class="n">active_logger</span>
<span class="kn">from</span> <span class="nn">.utilities</span> <span class="kn">import</span> <span class="n">export_to_all</span><span class="p">,</span> <span class="n">flatten</span>

<span class="n">DEFAULT_PRIORITY</span> <span class="o">=</span> <span class="mi">0</span>  <span class="c1"># Lowest possible priority.</span>

<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;DEFAULT_PRIORITY&quot;</span><span class="p">]</span>


<span class="k">class</span> <span class="nc">DesignClass</span><span class="p">(</span><span class="n">ABC</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Base class for design elements with prioritized attributes.</span>
<span class="sd">    </span>
<span class="sd">    This class serves as a foundation for design elements that need to be</span>
<span class="sd">    categorized and prioritized within a circuit design. It provides basic</span>
<span class="sd">    functionality for storing attributes and comparing design classes.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="o">**</span><span class="n">attribs</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initialize a design class with a name and attributes.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            name (str): The name of the design class</span>
<span class="sd">            **attribs: Additional attributes for the design class.</span>
<span class="sd">                      If &#39;priority&#39; is not specified, DEFAULT_PRIORITY is used.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># Assign part class name.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>

        <span class="c1"># Assign default priority if not specified.</span>
        <span class="k">if</span> <span class="s2">&quot;priority&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">attribs</span><span class="p">:</span>
            <span class="n">attribs</span><span class="p">[</span><span class="s2">&quot;priority&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">DEFAULT_PRIORITY</span>

        <span class="c1"># Assign the other attributes to this object.</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">attribs</span><span class="o">.</span><span class="n">items</span><span class="p">()):</span>
            <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">cls</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Check equality between two DesignClass instances.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            cls: Object to compare with this instance</span>
<span class="sd">            </span>
<span class="sd">        Returns:</span>
<span class="sd">            bool: True if both objects are DesignClass instances with identical attributes</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">DesignClass</span><span class="p">):</span>
            <span class="k">return</span> <span class="kc">False</span>
        
        <span class="c1"># Compare all attributes of both objects</span>
        <span class="k">return</span> <span class="nb">vars</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">==</span> <span class="nb">vars</span><span class="p">(</span><span class="bp">cls</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__hash__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Generate hash value based on the design class name.</span>
<span class="sd">        </span>
<span class="sd">        Returns:</span>
<span class="sd">            int: Hash value of the name attribute</span>

<span class="sd">        Note:</span>
<span class="sd">            An explicit hash function is needed since an __eq__ function was defined.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">hash</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>

<div class="viewcode-block" id="PartClass">
<a class="viewcode-back" href="../../rst_output/skidl.design_class.html#skidl.design_class.PartClass">[docs]</a>
<span class="nd">@export_to_all</span>
<span class="k">class</span> <span class="nc">PartClass</span><span class="p">(</span><span class="n">DesignClass</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A design class specifically for categorizing electronic parts.</span>
<span class="sd">    </span>
<span class="sd">    PartClass extends DesignClass to provide part-specific functionality</span>
<span class="sd">    and automatic registration with a circuit&#39;s part class collection.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">circuit</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">attribs</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initialize a part class and register it with a circuit.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            name (str): The name of the part class</span>
<span class="sd">            circuit (Circuit, optional): Circuit to register with. </span>
<span class="sd">                                       Uses default_circuit if not specified.</span>
<span class="sd">            **attribs: Additional attributes for the part class</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="o">**</span><span class="n">attribs</span><span class="p">)</span>

        <span class="c1"># This object will belong to the default Circuit object or the one</span>
        <span class="c1"># that&#39;s passed as a parameter.</span>
        <span class="n">circuit</span> <span class="o">=</span> <span class="n">circuit</span> <span class="ow">or</span> <span class="n">default_circuit</span>
        <span class="n">circuit</span><span class="o">.</span><span class="n">partclasses</span> <span class="o">=</span> <span class="bp">self</span></div>


<div class="viewcode-block" id="NetClass">
<a class="viewcode-back" href="../../rst_output/skidl.design_class.html#skidl.design_class.NetClass">[docs]</a>
<span class="nd">@export_to_all</span>
<span class="k">class</span> <span class="nc">NetClass</span><span class="p">(</span><span class="n">DesignClass</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A design class specifically for categorizing electrical nets.</span>
<span class="sd">    </span>
<span class="sd">    NetClass extends DesignClass to provide net-specific functionality</span>
<span class="sd">    and automatic registration with a circuit&#39;s net class collection.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">circuit</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">attribs</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initialize a net class and register it with a circuit.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            name (str): The name of the net class</span>
<span class="sd">            circuit (Circuit, optional): Circuit to register with.</span>
<span class="sd">                                       Uses default_circuit if not specified.</span>
<span class="sd">            **attribs: Additional attributes for the net class</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="o">**</span><span class="n">attribs</span><span class="p">)</span>

        <span class="c1"># This object will belong to the default Circuit object or the one</span>
        <span class="c1"># that&#39;s passed as a parameter.</span>
        <span class="n">circuit</span> <span class="o">=</span> <span class="n">circuit</span> <span class="ow">or</span> <span class="n">default_circuit</span>
        <span class="n">circuit</span><span class="o">.</span><span class="n">netclasses</span> <span class="o">=</span> <span class="bp">self</span></div>


<span class="k">class</span> <span class="nc">DesignClasses</span><span class="p">(</span><span class="n">ABC</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A dictionary-based collection for managing design classes.</span>
<span class="sd">    </span>
<span class="sd">    This class provides a specialized dictionary for storing and managing</span>
<span class="sd">    collections of DesignClass objects with enhanced functionality for</span>
<span class="sd">    adding, retrieving, and organizing design classes.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">classes</span><span class="p">,</span> <span class="n">circuit</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">classes_name</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initialize a design classes collection.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            *classes: Variable number of design classes to add initially</span>
<span class="sd">            circuit (Circuit, optional): Associated circuit object</span>
<span class="sd">            classes_name (str, optional): Attribute name for this collection</span>
<span class="sd">                within a Circuit object such as &#39;partclasses&#39; or &#39;netclasses&#39;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

        <span class="c1"># Save the attribute name for referencing this collection in the Circuit object.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">classes_name</span> <span class="o">=</span> <span class="n">classes_name</span>

        <span class="c1"># Add an initial set of class objects.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">classes</span><span class="p">,</span> <span class="n">circuit</span><span class="o">=</span><span class="n">circuit</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">classes</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Check equality between two DesignClasses collections.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            classes: Another DesignClasses object to compare with this collection</span>
<span class="sd">            </span>
<span class="sd">        Returns:</span>
<span class="sd">            bool: True if both objects are of the same type with identical attributes</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">classes</span><span class="p">,</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">)):</span>
            <span class="k">return</span> <span class="nb">vars</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">==</span> <span class="nb">vars</span><span class="p">(</span><span class="n">classes</span><span class="p">)</span>
        <span class="k">return</span> <span class="kc">False</span>

    <span class="k">def</span> <span class="fm">__contains__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">cls</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Check if a specific design class is contained in this collection.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            cls (str or DesignClass): Class name or class object to search for</span>
<span class="sd">            </span>
<span class="sd">        Returns:</span>
<span class="sd">            bool: True if the class is found in the collection</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="c1"># If only given the class name, fetch the class object from the collection.</span>
            <span class="k">return</span> <span class="bp">cls</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
        <span class="k">return</span> <span class="bp">cls</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">values</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">names</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Retrieve design classes by name(s).</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            *names: One or more class names to retrieve</span>
<span class="sd">            </span>
<span class="sd">        Returns:</span>
<span class="sd">            DesignClass or list: Single class if one name provided,</span>
<span class="sd">                               list of classes if multiple names provided</span>
<span class="sd">                               </span>
<span class="sd">        Raises:</span>
<span class="sd">            KeyError: If a requested class name is not found</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">names</span> <span class="o">=</span> <span class="n">flatten</span><span class="p">(</span><span class="n">names</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">names</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__getitem__</span><span class="p">(</span><span class="n">names</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                <span class="n">active_logger</span><span class="o">.</span><span class="n">raise_</span><span class="p">(</span>
                    <span class="ne">KeyError</span><span class="p">,</span> <span class="sa">f</span><span class="s2">&quot;No </span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="si">}</span><span class="s2"> with name &#39;</span><span class="si">{</span><span class="n">names</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="si">}</span><span class="s2">&#39; found&quot;</span>
                <span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">names</span> <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">classes</span><span class="p">,</span> <span class="n">circuit</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add one or more design classes to the collection.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            *classes: Variable number of classes to add. Can be DesignClass objects,</span>
<span class="sd">                     strings (class names), lists, tuples, or other DesignClasses</span>
<span class="sd">            circuit (Circuit, optional): Circuit to associate with new classes</span>
<span class="sd">            </span>
<span class="sd">        Raises:</span>
<span class="sd">            ValueError: If attempting to add a class with the same name but different attributes</span>
<span class="sd">            TypeError: If attempting to add an unsupported type</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="bp">cls</span> <span class="ow">in</span> <span class="n">classes</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">cls</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">DesignClasses</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="o">*</span><span class="bp">cls</span><span class="o">.</span><span class="n">values</span><span class="p">(),</span> <span class="n">circuit</span><span class="o">=</span><span class="n">circuit</span><span class="p">)</span>  <span class="c1"># Recursively add classes from another DesignClasses object.</span>
                <span class="k">continue</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">,</span> <span class="nb">set</span><span class="p">)):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="o">*</span><span class="bp">cls</span><span class="p">,</span> <span class="n">circuit</span><span class="o">=</span><span class="n">circuit</span><span class="p">)</span>  <span class="c1"># Recursively add classes from a list, tuple, or set.</span>
                <span class="k">continue</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">DesignClass</span><span class="p">):</span>
                <span class="k">if</span> <span class="bp">cls</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="k">if</span> <span class="bp">cls</span><span class="o">.</span><span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                    <span class="c1"># A NetClass with the same name exists but the attributes differ.</span>
                    <span class="n">active_logger</span><span class="o">.</span><span class="n">raise_</span><span class="p">(</span>
                        <span class="ne">ValueError</span><span class="p">,</span> <span class="sa">f</span><span class="s2">&quot;Cannot add </span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="bp">cls</span><span class="p">)</span><span class="si">}</span><span class="s2"> &#39;</span><span class="si">{</span><span class="bp">cls</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2">&#39; with differing attributes&quot;</span>
                    <span class="p">)</span>
                <span class="k">pass</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
                <span class="c1"># The name of a class was passed, so look it up in the circuit.</span>
                <span class="n">circuit</span> <span class="o">=</span> <span class="n">circuit</span> <span class="ow">or</span> <span class="n">default_circuit</span>
                <span class="bp">cls</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">circuit</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">classes_name</span><span class="p">)[</span><span class="bp">cls</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">active_logger</span><span class="o">.</span><span class="n">raise_</span><span class="p">(</span>
                    <span class="ne">TypeError</span><span class="p">,</span>
                    <span class="sa">f</span><span class="s2">&quot;Can&#39;t add </span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="bp">cls</span><span class="p">)</span><span class="si">}</span><span class="s2"> to </span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">,</span>
                <span class="p">)</span>
            <span class="c1"># Add the partclass to the list if it&#39;s not already present.</span>
            <span class="k">if</span> <span class="bp">cls</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">:</span>
                <span class="bp">self</span><span class="p">[</span><span class="bp">cls</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="bp">cls</span>

    <span class="k">def</span> <span class="nf">by_priority</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get class names sorted by priority.</span>
<span class="sd">        </span>
<span class="sd">        Returns:</span>
<span class="sd">            list: List of class names ordered by their priority attribute</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">pc</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">pc</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">values</span><span class="p">(),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">pc</span><span class="p">:</span> <span class="n">pc</span><span class="o">.</span><span class="n">priority</span><span class="p">)]</span>
    
<span class="k">class</span> <span class="nc">PartClasses</span><span class="p">(</span><span class="n">DesignClasses</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Specialized collection for managing part classes.</span>
<span class="sd">    </span>
<span class="sd">    This class extends DesignClasses to provide specific functionality</span>
<span class="sd">    for organizing and managing electronic part classifications.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">classes</span><span class="p">,</span> <span class="n">circuit</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initialize a part classes collection.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            *classes: Variable number of part classes to add initially</span>
<span class="sd">            circuit (Circuit, optional): Associated circuit object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">classes</span><span class="p">,</span> <span class="n">circuit</span><span class="o">=</span><span class="n">circuit</span><span class="p">,</span> <span class="n">classes_name</span><span class="o">=</span><span class="s2">&quot;partclasses&quot;</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">NetClasses</span><span class="p">(</span><span class="n">DesignClasses</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Specialized collection for managing net classes.</span>
<span class="sd">    </span>
<span class="sd">    This class extends DesignClasses to provide specific functionality</span>
<span class="sd">    for organizing and managing electrical net classifications.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">classes</span><span class="p">,</span> <span class="n">circuit</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initialize a net classes collection.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            *classes: Variable number of net classes to add initially</span>
<span class="sd">            circuit (Circuit, optional): Associated circuit object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">classes</span><span class="p">,</span> <span class="n">circuit</span><span class="o">=</span><span class="n">circuit</span><span class="p">,</span> <span class="n">classes_name</span><span class="o">=</span><span class="s2">&quot;netclasses&quot;</span><span class="p">)</span>
</pre></div>

            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
<search id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SKiDL 2.2.0 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">skidl.design_class</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
    &#169; Copyright 2016-2025, Dave Vandenbout.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
    </div>
  </body>
</html>